package org.rocky.provider.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Rocky
 * @date 2020/2/17 17:42
 */
@RestController
@RequestMapping("/provider/topic")
public class SendTopicController {

    private RabbitTemplate rabbitTemplate;

    @Autowired
    public SendTopicController(RabbitTemplate rabbitTemplate){
        this.rabbitTemplate = rabbitTemplate;
    }

    @RequestMapping("/prefix")
    public String sendPrefixTopicMsg(String info){
        String msg = ""+info;
        Message message = new Message(msg.getBytes(),new MessageProperties());
        rabbitTemplate.send("TOPIC_EXCHANGE","rocky.*",message);
        return "success";
    }


    @RequestMapping("/suffix")
    public String sendSuffixTopicMsg(String info){
        String msg = ""+info;
        Message message = new Message(msg.getBytes(),new MessageProperties());
        rabbitTemplate.send("TOPIC_EXCHANGE","*.exchange",message);
        return "success";
    }
}
